<template>
	<view class="tab_content">
		<form>
			<view class="cu-form-group margin-top">
				<view class="title">农场名称</view>
				<picker @change="PickerChange1" range-key="nc_mc" :value="sel1"  :range="ncpicker">
					<view class="picker">
						{{sel1>-1?ncpicker[sel1].nc_mc:'请选择'}}
					</view>
				</picker>
			</view>
			<view class="cu-form-group margin-top">
				<view class="title">管理区名称</view>
				<picker @change="PickerChange2" range-key="glq_mc" :value="sel2"  :range="glqpicker">
					<view class="picker"  v-if="glqpicker.length>0">
						{{sel2>-1&&glqpicker[sel2].glq_mc?glqpicker[sel2].glq_mc:'请先选择农场名称'}}
					</view>
				</picker>
				<view v-if='glqpicker.length==0' class="deftxt">请先选择农场名称</view>
			</view>
			<view class="cu-form-group margin-top">
				<view class="title">地块名称</view>
				<picker @change="PickerChange3" range-key="dk_mc" :value="sel3" :range="dkpicker">
					<view class="picker"  v-if="dkpicker.length>0">
						{{sel3>-1&&dkpicker[sel3].dk_mc?dkpicker[sel3].dk_mc:'请先选择管理区名称'}}
					</view>
				</picker>
				<view v-if='dkpicker.length==0' class="deftxt">请先选择管理区名称</view>
			</view>
			<view class="cu-form-group margin-top">
				<view class="title">监测点</view>
				<picker @change="PickerChange4" range-key="deviceid" :value="sel4" :range="jcdpicker">
					<view class="picker" v-if="jcdpicker.length>0">
						{{sel4>-1&&jcdpicker[sel4].deviceid?jcdpicker[sel4].deviceid:'请先选择地块名称'}}
					</view>
				</picker>
				<view v-if='jcdpicker.length==0' class="deftxt">请先选择地块名称</view>
			</view>
			<view class="padding flex">
				<button class="flex-sub cu-btn block bg-blue margin-sm lg" @tap="openurl('sjcx_res')">查询</button>
				<button class="flex-sub cu-btn block bg-blue margin-sm lg" @tap="clearsle()">重置</button>
			</view>
		</form>
	</view>
</template>

<script>
	import {getncxxlist,getglqxxlist,getdkxxlist,getsblbcxbyid,getsjcxsjd} from '../api/api.js'
	export default {
		data() {
			return {
				sel1: -1,
				sel2: -1,
				sel3: -1,
				sel4: -1,
				ncpicker:[],
				glqpicker:[],
				dkpicker:[],
				jcdpicker:[]
				};
			},
			onShow(){
				let _this=this;
				getncxxlist(      //农场数据
					function(res){
						_this.ncpicker=res.data.returnData.ncxxlb;
					}
				)
			},
			methods: {
					setselback(){
					
						this.sel2= -1;
						this.sel3= -1;
						this.sel4= -1;
						this.glqpicker=[];
						this.dkpicker=[];
						this.jcdpicker=[];
					},
					PickerChange1(e) {
						let _this=this
						if(e.detail.value==-1 ) e.detail.value=0
						this.sel1 = e.detail.value;
						this.setselback()
					    let parm ={
							cx_ssnc:this.ncpicker[this.sel1].nc_bh
						} 
						getglqxxlist(      //管理区数据
							parm,
							function(res){
								_this.glqpicker=res.data.returnData.glqxxlb||[];	
							}
						)
					},
					PickerChange2(e) {
						let _this=this
						if(e.detail.value==-1 ) e.detail.value=0
						this.sel2 = e.detail.value;
	
						let parm={cx_ssjd:this.glqpicker[this.sel2].glq_bh}
						getdkxxlist(parm,
						function (res) {
							_this.dkpicker=res.data.returnData.dkxxlb||[]
						}
						)
					},
					PickerChange3(e) {
						if(e.detail.value==-1 ) e.detail.value=0
						this.sel3 = e.detail.value
						
						let parm={dk_bh:this.dkpicker[this.sel3].dk_bh}
						getsblbcxbyid(parm,
						res=>{
							this.jcdpicker=res.data.returnData.sbxxlb||[]
						}
						)
					},
					PickerChange4(e) {
						if(e.detail.value==-1 ) e.detail.value=0
						this.sel4 = e.detail.value
					},
					clearsle(){
						this.sel1= -1,
						this.sel2= -1,
						this.sel3= -1,
						this.sel4= -1
					},
					openurl(url) {
						if((this.dkpicker[this.sel3]&&this.dkpicker[this.sel3].dk_bh)&&(this.jcdpicker[this.sel4]&&this.jcdpicker[this.sel4].deviceid)){
							let parm={dk_bh:this.dkpicker[this.sel3].dk_bh,deviceId:this.jcdpicker[this.sel4].deviceid}
							getsjcxsjd(parm,
							res=>{
							
								let data=JSON.stringify(res.data.returnData.sjcx_xq)
								uni.navigateTo({
									url: url+'?sjcx_xq='+data+'&dk_bh='+this.dkpicker[this.sel3].dk_bh+'&deviceId='+this.jcdpicker[this.sel4].deviceid
								}); 
							})
						}else{
							uni.showModal({
							    title: '提示',
							    content: '请选择地块名称和监测点',
								showCancel:false
							});
						}
						
						
					}
			}
		}
</script>

<style scoped>
	@import "../../colorui/main.css";
	@import "../../colorui/icon.css";
</style>
